<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Color Manila Run - Register</title>
<link rel="stylesheet" href="../styles/layout.css" type="text/css" media="screen"/>
<script src="../scripts/jquery-1.8.2.js"></script>
<script src="../scripts/jquery.format.1.05.js"></script>
<script src="../scripts/preloadercontrol.js"></script>
<script src="../scripts/register.js"></script>
<script src="../scripts/textinputUtils.js"></script>
<script src="../scripts/inputTextMask.js"></script>

</head>
<body marginheight="0" marginwidth="0">
<div id="preloader"><div><img src="../images/ajax-loader.gif" width="50" height="50"/></div></div>
<div id="regMainContainer">
	<div id="registerHeader">
		<div class="registerHeaderImg"><img src="../images/registration_header.png" alt="Registration"/></div>
		<div class="registerSteps">
			<div style="width:130px;">
				<div class="regStepIcon" style="padding-left:50px;"><img id="imgStep1" src="../images/reg_done_step.png" width="20" height="20"/></div>
			</div>
			<div style="width: 100px;">
				<div class="regStepIcon"><img id="imgStep2" src="../images/reg_done_step.png" width="20" height="20"/></div>
			</div>
			<div>
				<div class="regStepIcon"><img id="imgStep3" src="../images/reg_done_step.png" width="20" height="20"/></div>
			</div>
			<div>
				<div class="regStepIcon" ><img id="imgStep4" src="../images/reg_done_step.png" width="20" height="20"/></div>
			</div>
			<div>
				<div class="regStepIcon" ><img id="imgStep5" src="../images/reg_current_step.png" width="20" height="20"/></div>
			</div>
		</div>
		<div class="registerSteps">
			<div style="width:130px;">
				<div>&nbsp;&nbsp;Select Category</div>
			</div>
			<div style="width: 90px;">
				<div>&nbsp;&nbsp;Sign in</div>
			</div>
			<div style="width: 120px;">
				<div>Complete Form</div>
			</div>
			<div>
				<div>Review cart</div>
			</div>
			<div>
				<div>Check out</div>
			</div>
		</div>
	</div>
	<div id="registerContent">
	<?php
	require_once '../conn/DBconnect.php';
	require_once '../email/registration.php';
	
	session_start();
	$paypalStatus = "";
	$temprow = null;
	
	if(isset($_GET["st"]))
		$paypalStatus = $_GET["st"];
	
	if(isset($_GET["transID"]) && $paypalStatus == "Completed")
	{
		$tempRec[0] = "GET_TEMP_RECORD";
		$tempRec[1] = "0";
	 	$tempRec[2] = "";
	 	$tempRec[3] = "";
	 	$tempRec[4] = "";
	 	$tempRec[5] = "";
	 	$tempRec[6] = "";
	 	$tempRec[7] = "";
	 	$tempRec[8] = "";
	 	$tempRec[9] = "";
	 	$tempRec[10] = "";
	 	$tempRec[11] = "";
	 	$tempRec[12] = "";
	 	$tempRec[13] = "";
	 	$tempRec[14] = "";
	 	$tempRec[15] = "";
	 	$tempRec[16] = "";
	 	$tempRec[17] = "";
	 	$tempRec[18] = "";
	 	$tempRec[19] = "0";
	 	$tempRec[20] = "0";
	 	$tempRec[21] = "0";
	 	$tempRec[22] = "";
	 	$tempRec[23] = "";
	 	$tempRec[24] = $_GET["transID"];
		
		$tempRecPROC = "CALL SP_REGISTRATION('" . implode("', '", $tempRec) . "');";
		
		$result = mysqli_query($mysqlLink, $tempRecPROC);
		
		$withAddedRunner = false;
		if($result->num_rows > 1)
			$withAddedRunner = true;
		
	 	$temprow = mysqli_fetch_array($result, MYSQLI_ASSOC);
	 	
		if(isset($_SESSION['paypalToken']) && isset($_SESSION['paypalPayerID']))
		{
			unset($_SESSION['paypalToken']);
			unset($_SESSION['paypalPayerID']);
		}
	
	 	if( $temprow["err_id"] != '-1')
	 	{
	 	?>
	 		<div id="registrationPrint" style="width:400px;text-align: center;">
				<div><img src="../images/cmr_logo.png"/></div>
				<div class="divSpacer"></div>
				<div class="divSpacer"></div>
				<div><img src="../images/proactive_logo.png"/></div>
				
				<div style="text-align: center;">
					<h2>Thanks for coming</h2>
					<h2>-and-</h2>
					<h2>Thank you for signing up!</h2>
					<br>
					<div style="padding-left: 30px;">
						<div style="text-align: left;">Details of your registration are as follows:</div>
						<div style="text-align: left;"><b>Registration No.: <?php echo $temprow["pi_code"]?></b></div>
						<div style="text-align: left;"><b>Registration Date: <?php echo $temprow["pi_crd"]?></b></div>
						<div style="text-align: left;"><b>Participant	: <?php echo $temprow["pi_first_name"]." ".$temprow["pi_last_name"]." ".$temprow["pi_middle_initial"]?></b></div>
						<div style="text-align: left;"><b>BirthDate		: <?php echo $temprow["pi_birthdate"] ?></b></div>
						<div style="text-align: left;"><b>Gender		: <?php echo $temprow["pi_gender"] ?></b></div>
						<div style="text-align: left;"><b>Race Category	: <?php echo $temprow["pi_race_code"] ?></b></div>
						<div style="text-align: left;"><b>Singlet		: <?php echo $temprow["pi_size"] ?></b></div>
						<div style="text-align: left;"><b>Color		: <?php echo $temprow["pi_color"] ?></b></div>
						<br>
						<div style="text-align: left;"><b>Fee		: Php <?php echo $temprow["totalRegFee"]?></b></div>
											
						<?php echo RegEmail::emailNotificationText(); ?>
					</div>
				</div>
			</div>
			
		<?php 
			
			if(isset($_SESSION['isRegistered']) && $_SESSION['isRegistered'] == false)
				$_SESSION['isRegistered'] = true;
		
			$message = '
				<html>
				<head>
				  <title>Color Manila Run</title>
				</head>
				<body>
				  <div><img src="http://www.proactive.ph/colormanilarun/images/cmr_logo.jpg"/></div>
				  <div class="divSpacer"></div>
					<div><img src="http://www.proactive.ph/colormanilarun/images/proactive_logo.png"/></div>
					
					<h2>Thank you for signing up!</h2>
					<br>
					<div style="padding-left: 30px;">
						<div style="text-align: left;">Details of your registration are as follows:</div>
						<div style="text-align: left;"><b>Registration No.: ' . $temprow["pi_code"]. '</b></div>
						<div style="text-align: left;"><b>Registration Date: ' . $temprow["pi_crd"] . '</b></div>
						<div style="text-align: left;"><b>Participant	: ' . $temprow["pi_first_name"].' '.$temprow["pi_last_name"].' ' .$temprow["pi_middle_initial"] .'</b></div>
						<div style="text-align: left;"><b>BirthDate		: ' . $temprow["pi_birthdate"] . '</b></div>
						<div style="text-align: left;"><b>Gender		: ' . $temprow["pi_gender"] . '</b></div>
						<div style="text-align: left;"><b>Race Category	: ' . $temprow["pi_race_code"] . '</b></div>
						<div style="text-align: left;"><b>Singlet		: ' . $temprow["pi_size"] . '</b></div>
						<div style="text-align: left;"><b>Color		: ' . $temprow["pi_color"] . '</b></div>
						<br>
						<div style="text-align: left;"><b>Fee		: Php ' . $temprow["totalRegFee"]. '</b></div>
						<br>
						<span>You can now login at <a href="www.proactive.ph/colormanilarun">www.proactive.ph/colormanilarun</a> 
						using the temporary password: <b>'. $temprow["defaultPassword"].'</b> </span>
						'. RegEmail::emailNotificationText().'						
				</body>
				</html>
				';
			
			RegEmail::registrationComplete($temprow["pi_email_add"], $message);
	 	}

	 	echo "<input type=\"hidden\" name=\"err_id\" value=\"".$temprow["err_id"]."\"/>";
	 	
	 	mysqli_free_result($result);
		mysqli_next_result($mysqlLink); 
	 	mysqli_close($mysqlLink);
	 	
	}
	else
		echo "<h2>".$paypalStatus."</h2>";
		
?>
	
	</div>
	<div class="divSpacer"></div>
	<div id="registerButtonMenu">
		<div id="registerButton">
			<div class="blue-buttonBL"></div>
			<div id="btnContinue" class="blue-buttonM">
			<a href="../main.php">Home</a>
			</div>
			<div class="blue-buttonBR"></div>
		</div>
	</div>
</div>
</body>
<script type="text/javascript">
$("#preloader").css({ opacity: 0.5 });
showPreloader(false);
</script>
</html>